package com.irdstudio.cdp.pboc.service.impl;

import java.util.List;
import java.util.Objects;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.irdstudio.cdp.pboc.service.dao.PbocNearcreditStatusDao;
import com.irdstudio.cdp.pboc.service.domain.PbocNearcreditStatus;
import com.irdstudio.cdp.pboc.service.facade.PbocNearcreditStatusService;
import com.irdstudio.cdp.pboc.service.vo.PbocNearcreditStatusVO;
import com.irdstudio.basic.framework.core.base.FrameworkService;
/**
 * <p>ServiceImpl: 准贷记卡状态信息				<p>
 * @author ligm
 * @date 2018-12-26
 */
@Service("pbocNearcreditStatusService")
public class PbocNearcreditStatusServiceImpl implements PbocNearcreditStatusService, FrameworkService {
	
	private static Logger logger = LoggerFactory.getLogger(PbocNearcreditStatusServiceImpl.class);

	@Autowired
	private PbocNearcreditStatusDao pbocNearcreditStatusDao;
	
	/**
	 * 新增操作
	 */
	public int insertPbocNearcreditStatus(PbocNearcreditStatusVO inPbocNearcreditStatusVo)  throws Exception {
		logger.debug("当前新增数据为:"+ inPbocNearcreditStatusVo.toString());
		int num = 0;
		try {
			PbocNearcreditStatus pbocNearcreditStatus = new PbocNearcreditStatus();
			beanCopy(inPbocNearcreditStatusVo, pbocNearcreditStatus);
			num = pbocNearcreditStatusDao.insertPbocNearcreditStatus(pbocNearcreditStatus);
		} catch (Exception e) {
			logger.error("新增数据发生异常!", e);
			num = -1;
			throw e;
		}
		logger.debug("当前新增数据条数为:"+ num);
		return num;
	}

	/**
	 * 删除操作
	 */
	public int deleteByPk(PbocNearcreditStatusVO inPbocNearcreditStatusVo)  throws Exception {
		logger.debug("当前删除数据条件为:"+ inPbocNearcreditStatusVo);
		int num = 0;
		try {
			PbocNearcreditStatus pbocNearcreditStatus = new PbocNearcreditStatus();
			beanCopy(inPbocNearcreditStatusVo, pbocNearcreditStatus);
			num = pbocNearcreditStatusDao.deleteByPk(pbocNearcreditStatus);
		} catch (Exception e) {
			logger.error("删除数据发生异常!", e);
			num = -1;
			throw e;
		}
		logger.debug("根据条件:"+ inPbocNearcreditStatusVo +"删除的数据条数为"+ num);
		return num;
	}


	/**
	 * 更新操作
	 */
	public int updateByPk(PbocNearcreditStatusVO inPbocNearcreditStatusVo)  throws Exception {
		logger.debug("当前修改数据为:"+ inPbocNearcreditStatusVo.toString());
		int num = 0;
		try {
			PbocNearcreditStatus pbocNearcreditStatus = new PbocNearcreditStatus();
			beanCopy(inPbocNearcreditStatusVo, pbocNearcreditStatus);
			num = pbocNearcreditStatusDao.updateByPk(pbocNearcreditStatus);
		} catch (Exception e) {
			logger.error("修改数据发生异常!", e);
			num = -1;
			throw e;
		}
		logger.debug("根据条件:"+ inPbocNearcreditStatusVo +"修改的数据条数为"+ num);
		return num;
	}
	
	/**
	 * @description:根据贷记卡基本信息表的外键进行查询
	 * @param fids
	 * @return
	 * @date:2018年12月27日 下午8:06:07
	 * @author:hengyh
	 */
	@SuppressWarnings("unchecked")
	@Override
	public List<PbocNearcreditStatusVO> queryByFID(List<String> fids)  throws Exception {
		logger.debug("当前查询参数信息为:"+ fids);
		List<PbocNearcreditStatusVO> list = null;
		try {
			List<PbocNearcreditStatus> pbocLoadStatuss = pbocNearcreditStatusDao.queryByFID(fids);
			list = (List<PbocNearcreditStatusVO>) beansCopy(pbocLoadStatuss, PbocNearcreditStatusVO.class);
		} catch (Exception e) {
			logger.error("查询数据发生异常!", e);
			throw e;
		}
		return list;
	}

	/**
	 * 需求编号:2019D0519
	 * 问题编号:
	 * 开发人员: caoxin
	 * 创建日期:2019/7/19
	 * 功能描述:准贷记卡状态记录
	 * 修改日期:2019/7/19
	 * 修改描述:
	 */
	public PbocNearcreditStatusVO queryByPk(PbocNearcreditStatusVO inPbocNearcreditStatusVo) {
		
		logger.debug("当前查询参数信息为:"+ inPbocNearcreditStatusVo);
		try {
			PbocNearcreditStatus queryPbocNearcreditStatus = new PbocNearcreditStatus();
			beanCopy(inPbocNearcreditStatusVo, queryPbocNearcreditStatus);
			PbocNearcreditStatus queryRslPbocNearcreditStatus = pbocNearcreditStatusDao.queryByPk(queryPbocNearcreditStatus);
			if (Objects.nonNull(queryRslPbocNearcreditStatus)) {
				PbocNearcreditStatusVO outPbocNearcreditStatusVo = beanCopy(queryRslPbocNearcreditStatus, new PbocNearcreditStatusVO());
				logger.debug("当前查询结果为:"+ outPbocNearcreditStatusVo.toString());
				return outPbocNearcreditStatusVo;
			} else {
				logger.debug("当前查询结果为空!");
			}
		} catch (Exception e) {
			logger.error("查询数据发生异常!", e);
			throw e;
		}
		return null;
	}


	/**
	 * 查询用户权限数据
	 */
	@SuppressWarnings("unchecked")
	public List<PbocNearcreditStatusVO> queryAllOwner(PbocNearcreditStatusVO pbocNearcreditStatusVo)  throws Exception {

		logger.debug("当前查询本人所属数据信息的参数信息为:");
		List<PbocNearcreditStatusVO> list = null;
		try {
			List<PbocNearcreditStatus> pbocNearcreditStatuss = pbocNearcreditStatusDao.queryAllOwnerByPage(pbocNearcreditStatusVo);
			logger.debug("当前查询本人所属数据信息的结果集数量为:"+ pbocNearcreditStatuss.size());
			pageSet(pbocNearcreditStatuss, pbocNearcreditStatusVo);
			list = (List<PbocNearcreditStatusVO>) beansCopy(pbocNearcreditStatuss, PbocNearcreditStatusVO.class);
		} catch (Exception e) {
			logger.error("数据转换出现异常!", e);
			throw e;
		}
		
		return list;
	
	}


	/**
	 * 查询当前机构权限数据
	 */
	@SuppressWarnings("unchecked")
	public List<PbocNearcreditStatusVO> queryAllCurrOrg(PbocNearcreditStatusVO pbocNearcreditStatusVo)  throws Exception {

		logger.debug("当前查询本人所属机构数据信息的参数信息为:");
		List<PbocNearcreditStatus> pbocNearcreditStatuss = pbocNearcreditStatusDao.queryAllCurrOrgByPage(pbocNearcreditStatusVo);
		logger.debug("当前查询本人所属机构数据信息的结果集数量为:"+pbocNearcreditStatuss.size());
		List<PbocNearcreditStatusVO> list = null;
		try {
			pageSet(pbocNearcreditStatuss, pbocNearcreditStatusVo);
			list = (List<PbocNearcreditStatusVO>) beansCopy(pbocNearcreditStatuss, PbocNearcreditStatusVO.class);
		} catch (Exception e) {
			logger.error("数据转换出现异常!", e);
			throw e;
		}
		
		return list;
	
	}


	/**
	 * 查询当前机构及下属机构权限数据
	 */
	@SuppressWarnings("unchecked")
	public List<PbocNearcreditStatusVO> queryAllCurrDownOrg(PbocNearcreditStatusVO pbocNearcreditStatusVo)  throws Exception {

		logger.debug("当前查询本人所属机构及以下数据信息的参数信息为:");
		List<PbocNearcreditStatus> pbocNearcreditStatuss = pbocNearcreditStatusDao.queryAllCurrDownOrgByPage(pbocNearcreditStatusVo);
		logger.debug("当前查询本人所属机构及以下数据信息的结果集数量为:"+ pbocNearcreditStatuss.size());
		List<PbocNearcreditStatusVO> list = null;
		try {
			pageSet(pbocNearcreditStatuss, pbocNearcreditStatusVo);
			list = (List<PbocNearcreditStatusVO>) beansCopy(pbocNearcreditStatuss, PbocNearcreditStatusVO.class);
		} catch (Exception e) {
			logger.error("数据转换出现异常!", e);
			throw e;
		}
		
		return list;
	
	}
}
